<template>
  <div style="height:430px;">
    <el-row style="padding-top:20px;height:100%;">
      <el-col :span="6" class="colImg">
        <img src="../../assets/images/zaixian.png" alt="">
      </el-col>
      <el-col :span="18" style="padding-left:20px;">
        <div class="formDiv">
          <div v-if="lineType=='ukey'" style="width：75%">
            <el-button type="primary" @click="search('search')">查询</el-button><span>（请确认插入产品授权Ukey后，点击查询按钮）</span>
            <el-row style="margin-top:25px">
              <el-col :span="10">
                <p class="text-content">授权用户单位名称：</p>
              </el-col>
              <el-col :span="14">
                <p class="text-align">{{authInfoList.orgName|defaultText}}</p>
              </el-col>
            </el-row>
            <el-row style="margin:25px 0">
              <el-col :span="10">
                <p class="text-content">授权许可总数：</p>
              </el-col>
              <el-col :span="14">
                <p class="text-align">{{authInfoList.totalLicense|defaultText}}</p>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="10">
                <p class="text-content">授剩余可用许可数：</p>
              </el-col>
              <el-col :span="14">
                <p class="text-align">{{authInfoList.residualLicense|defaultText}}</p>
              </el-col>
            </el-row>
          </div>
          <el-row v-else style="width:70%">
            <el-row>
              <el-col :span="20">
                <el-upload class="upload-demo" action="#" :show-file-list="false" :on-change="handleChange"
                  :file-list="fileList" :auto-upload="false" style="text-align: center;">
                  <el-button type="primary">导入</el-button>
                  <span slot="tip" class="el-upload__tip" style="margin-left:5px">点击此可上传授权文件</span>
                </el-upload>
              </el-col>
              <!-- <el-col :span="14">
                <p class="text-align">{{fileName|defaultText}}</p>
              </el-col> -->
            </el-row>
            <el-col :span="18" style="margin-top:10px">
              <p style="text-align: center;">{{fileName|defaultText}}</p>
            </el-col>
            <el-col :span="10" style="margin:25px 0">
              <p class="text-content">主机序列号：</p>
            </el-col>
            <el-col :span="14" style="margin:25px 0">
              <p class="text-align">{{serialnumber|defaultText}}</p>
            </el-col>
            <!-- <el-col :span="10" style="margin:25px 0">
              <p class="text-content">授权类型：</p>
            </el-col>
            <el-col :span="14" style="margin:25px 0">
              <p class="text-align">{{softList.totalLicense|defaultText}}</p>
            </el-col>
            <el-col :span="10">
              <p class="text-content">授权用户单位：</p>
            </el-col>
            <el-col :span="14">
              <p class="text-align">{{softList.orgName|defaultText}}</p>
            </el-col>
            <el-col :span="10" style="margin:25px 0">
              <p class="text-content">主机序列号列表：</p>
            </el-col>
            <el-col :span="14" style="margin:25px 0">
              <p class="text-align">{{softList.totalLicense|defaultText}}</p>
            </el-col>
            <el-col :span="10">
              <p class="text-content">授权时间：</p>
            </el-col>
            <el-col :span="14">
              <p class="text-align">{{softList.totalLicense|defaultText}}</p>
            </el-col> -->
          </el-row>
        </div>
        <div class="deploy-btn">
          <el-button type="primary" @click.native="search('next')" v-if="lineType=='ukey'">下一步</el-button>
          <el-button type="primary" @click.native="softnext" v-if="lineType=='license'">下一步</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  props: {
    lineType: {
      type: String
    }
  },
  data() {
    return {
      authInfoList: {
        orgName: '',
        totalLicense: '',
        residualLicense: ''
      },
      form1: {},
      nextShow: true,
      show: '1',
      fileList: [],
      reqId: '',
      softList: {},
      msgFile: '',
      serialnumber: '',
      fileName: '',
      operatingSystem:sessionStorage.getItem('operatingSystem')
    }
  },
  created() {
    // this.soft()
    // this.getserial()
  },
  mounted() {
    // this.getserial()
  },
  methods: {
    getserial() {
      this.$get('vgmp/config/getserialnumber').then(res => {
        let { data, result } = res.data
        // if (!result) {
        //   return false
        // }
        // console.log(data);
        this.serialnumber = data.data
      })
    },
    getUUID() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
      })
    },
    search(type) {
      console.log(this.reqId, 789);
      let param = {}
      if (type == 'search') {
        param = {
          data: {
            method: 'queryAuthorizationInfo',
            reqId: this.getUUID(),
            msg: ''
          }
        }
      } else {
        param = {
          data: {
            method: 'authorizedApplication',
            reqId: this.reqId,
            msg: ''
          }
        }
      }
      this.$postForJson('vgmp/config/checkauthorization', param).then(res => {
        let data = res.data.data;
        if (!data.result) {
          this.$message.error('获取失败')
          return false
        }
        if (type == 'next') {
          this.$alert('保存成功！', '提示', {
            confirmButtonText: '确定',
            type: 'primary'
          }).then(() => {
            this.$emit('product')
          }).catch(() => {
          });
        } else {
          console.log(data.reqId, 32);
          this.reqId = data.reqId;
          if(data.authInfoList !==[] || data.authInfoList !== null) {
            this.authInfoList = data.authInfoList[0]
          }
        }

      })

    },
    soft() {
      let param = {
        data: {
          method: 'licenseAuthorized',
          reqId: '17ea58c0-1753-4c5e-a6b5-48407908fc83',
          msg: ''
        }
      }
      this.$postForJson('vgmp/config/checkauthorization', param).then(res => {
        let data = res.data.data;
        if (!data.result) {
          // this.$message.error('保存失败')
          return false
        }
        if (data.authInfoList !== [] || data.authInfoList !== null) {
          this.softList = data.authInfoList[0]
        }

      })
    },
    handleChange(file, fileList) {
      console.log(file);
      this.fileList = [file]
      this.fileName = file.name
      let str;
      if(this.operatingSystem=='Windows'){
        str=file.raw.path.lastIndexOf('\\')
      }else{
        str=file.raw.path.lastIndexOf('/')
      }
      this.msgFile = file.raw.path.slice(0, str)
      console.log(this.msgFile)
    },
    softnext() {
      let param = {
        data: {
          method: 'licenseAuthorized',
          reqId: '17ea58c0-1753-4c5e-a6b5-48407908fc83',
          msg: this.msgFile
        }
      }
      this.$postForJson('vgmp/config/checkauthorization', param).then(res => {
        let data = res.data.data;
        if (!data.result) {
          this.$message.error('保存失败')
          return false
        }
        this.$alert('保存成功！', '提示', {
          confirmButtonText: '确定',
          type: 'primary'
        }).then(() => {
          this.$emit('product')
        }).catch(() => {
        });
      })
    }
  },
  filters: {
    defaultText(value) {
      if (!value) return "-";
      else {
        return value;
      }
    },
  }
}
</script>

<style scoped>
.colImg {
  border-right: 1px solid #ddd;
  height: 410px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.inp {
  width: 100%;
}

.deploy-btn {
  position: fixed;
  text-align: right;
  bottom: 30px;
  right: 28%;
  /* background-color: #EEE; */
}
.deploy-btn1 {
  position: fixed;
  text-align: right;
  bottom: 40px;
  right: 45%;
  /* background-color: #EEE; */
}
.formDiv {
  width: 100%;
  height: 350px;
  border-radius: 10px;
  /* background: rgba(13, 68, 98, 0.6); */
  background: rgba(255, 255, 255, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  /* //   transform: translateY(-20px); */
}
img {
  width: 150px;
}
.text-content {
  text-align: end;
}
.text-align {
  text-align: start;
}
</style>